package com.lanou.tipsy.fragment.singer.detail;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;

import com.lanou.tipsy.R;
import com.lanou.tipsy.base.BaseFragment;
import com.lanou.tipsy.entity.singer.singers_mv.SMVData;


/**
 * Created by FengJun on 15/10/24.
 * 歌手-歌手详情-MV详情
 */
public class MvVideoFragment extends BaseFragment {
    public static final String TAG = "MvVideoFragment";
    private VideoView videoView;
    private TextView tv_video_mv;
    private Uri uri;
    private Context context;
    private String video_url;
    private SMVData data;
    private ImageView mvBackIv;


    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fr_mv_video, null);
        videoView = (VideoView) view.findViewById(R.id.video_mv);
        tv_video_mv = (TextView) view.findViewById(R.id.tv_video_mv);
        mvBackIv = (ImageView) view.findViewById(R.id.mvBackIv);
        mvBackIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().getSupportFragmentManager().popBackStack();
            }
        });
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Bundle bundle = getArguments();
        data = (SMVData) bundle.get("data");
        video_url = data.getMvList().get(0).getUrl();
        initView(getView());

    }


    //歌手-详细信息-mv界面mv播放方法
    private void initView(View view) {
        tv_video_mv.setText(data.getSongName());
        uri = Uri.parse(video_url);
        // 设置视频
        videoView.setMediaController(new MediaController(context));
        videoView.setVideoURI(uri);
        videoView.start();
        videoView.requestFocus();
    }
}
